import 'package:flutter/material.dart';
import 'package:jiaju_flutter/pages/home/index.dart';
import 'package:jiaju_flutter/pages/info/index.dart';
import 'package:jiaju_flutter/pages/mine/index.dart';
import 'package:jiaju_flutter/pages/search/index.dart';

class MasterPage extends StatefulWidget {
  MasterPage({Key key}) : super(key: key);

  @override
  _MasterPageState createState() => _MasterPageState();
}

class _MasterPageState extends State<MasterPage> {
  final _pageList = [
    HomePage(),
    SearchPage(),
    InfoPage(),
    MinePage(),
  ];
  final _bottomBarList = [
    BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
    BottomNavigationBarItem(icon: Icon(Icons.search), label: "搜索"),
    BottomNavigationBarItem(icon: Icon(Icons.info), label: "资讯"),
    BottomNavigationBarItem(icon: Icon(Icons.account_circle), label: "我的"),
  ];

  var _selectIndex = 0;
  var _pageControll = PageController();

  @override
  Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size;
    var width = size.width;
    var height = size.height;
    return Scaffold(
      body: Container(
        child: PageView.builder(
          itemBuilder: (BuildContext context, int index) {
            return _pageList[index];
          },
          scrollDirection: Axis.horizontal,
          controller: _pageControll,
          reverse: false,
          physics: NeverScrollableScrollPhysics(),
        ),
        width: width,
        height: height,
      ),
      bottomNavigationBar: BottomNavigationBar(
        selectedItemColor: Colors.green,
        currentIndex: _selectIndex,
        items: _bottomBarList,
        type: BottomNavigationBarType.fixed,
        onTap: (index) => {
          setState(() {
            _selectIndex = index;
            _pageControll.jumpToPage(index);
          })
        },
      ),
    );
  }
}
